package versi.vitro.oaiserviceprovider.service.validation.impl;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import versi.vitro.oaiserviceprovider.service.validation.api.ValidationService;
import versi.vitro.oaiserviceprovider.test.BaseTestCase;

public class ValidationServiceIntegrationTest extends BaseTestCase {

    private String schemaLocation = "catalog.xsd";
    private String schemaLocations[];
    @SuppressWarnings("unused")
    private String schemaXml;
    
    private String sourceXmlLocation = "catalog_test.xml";
    private String sourceXml;

    @BeforeClass
    public void setUp() {
	String schemaLocationList[] = { schemaLocation };
	schemaLocations = schemaLocationList;
	sourceXml = getGeneralHelper().readPackageResourceAsString(sourceXmlLocation, getClass());
	schemaXml = getGeneralHelper().readPackageResourceAsString(schemaLocation, getClass());
    }

    @Test
    public void runTests() throws Exception {
	testAddSchemaOperation();
	testValidateAgainstSchemaOperation();
	testValidateAgainstRIFCSOperation();
    }

    private void testAddSchemaOperation() throws Exception {
	ValidationService validationService = getValidationService();
	validationService.deleteSchemas();
	validationService.addSchemas(schemaLocations);
    }

    private void testValidateAgainstSchemaOperation() throws Exception {
	ValidationService validationService = getValidationService();
	final byte[] inByte = sourceXml.getBytes();
	validationService.validateAgainstSchemas(inByte);
    }
    
    private void testValidateAgainstRIFCSOperation() throws Exception {
	ValidationService validationService = getValidationService();
	final byte[] inByte =  getGeneralHelper().readFileAsString("C:/Users/Cyrus/Desktop/rif.xml").getBytes();
	validationService.validateAgainstSchemas(inByte);
    }
    
    
}
